package org.yefei.homeworkday21.two;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Company {
	/*
	 * 利用Map重做员工管理那一题:以工号作为key,员工对象作为value，仍然实现 原来的功能。 并保证雇佣新人的时候工号不能重复
	 */
	private String name;
	private String address;
	private String phoneNum;
	private String range;
	Map<String, Staff> map = new HashMap<>();

	public Company() {
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhoneNum() {
		return phoneNum;
	}

	public void setPhoneNum(String phoneNum) {
		this.phoneNum = phoneNum;
	}

	public String getRange() {
		return range;
	}

	public void setRange(String range) {
		this.range = range;
	}

	public Company(String name, String address, String phoneNum, String range) {
		this.name = name;
		this.address = address;
		this.phoneNum = phoneNum;
		this.range = range;
	}

	{
		map.put("001", new Staff("张量", 31, "男", "总裁", 30));
		map.put("002", new Staff("王芒", 30, "男", "总经理", 20));
		map.put("003", new Staff("李莉", 29, "女", "主管", 10));
		map.put("004", new Staff("赵斯", 27, "男", "HR", 5));
		map.put("005", new Staff("孙亚", 21, "女", "员工", 1));
	}

	// 招聘新员工
	public boolean addStaff(String k, Staff f) {
		if (!(map.containsKey(k))) {
			map.put(k, f);
			System.out.println("欢迎新人加入公司！");
			return true;
		}
		System.out.println("加入公司失败！");
		return false;
	}

	// 输出员工信息
	public void printStaff() {
		Set<String> keySet = map.keySet();
		for (String key : keySet) {
			Staff value = map.get(key);
			System.out.println(key + "" + value);
		}
	}

	// 辞退员工
	public boolean fireStaff(String yNum) {
		Set<String> keySet = map.keySet();
		for (String key : keySet) {
			Staff value = map.get(key);
			if (yNum.equals(key)) {
				map.remove(key);
				System.out.println("该员工已被删除！");
				return true;
			}
		}
		System.out.println("删除失败！");
		return false;
	}

	// 统计公司人数
	public int cal() {
		return map.size();
	}
}
